package org.NooLab.glue.subscription;

import java.util.Vector;

import org.NooLab.glue.MessageBoard;
import org.NooLab.glue.msgframe.MetaRegistration;
import org.NooLab.glue.msgframe.XRegistration;
import org.NooLab.glue.transaction.Transaction;
import org.NooLab.utilities.logging.PrintLog;

/**
 * 
 * 
 * 
 * 
 * 
 */
public class MessageMatcher implements MessageMatcherIntf{
	
	// =================================

	// object references ..............
	
	MessageBoard messageBoard ;
	MetaRegistration metaRegistration;
	
	// main variables / properties ....

	 
	// constants ......................
	
	

	// volatile variables .............

	
	
	// helper objects .................
	 
	PrintLog out;

	// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
	public MessageMatcher( MessageBoard msgboard, PrintLog outprn){
		
		messageBoard = msgboard;
		
		out = outprn;
		
		metaRegistration = messageBoard.getMetaRegistration() ;
		
	}
	// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
	
	
	
	/**
	 * <p>
	 * we need functionality (and xml tags) for comparing messages with subscriptions,
	 * even if the main message is "closed"  -> summary section, content description.</p> 
	 * The issuer of a transaction should be able to allow or disallow the description of 
	 * messages containing ResultPackages 
	 * 
	 */
	public long[] checkforSubscriptions( MMMessage mmmessage , long callingInstance){
										// avoid subscribing to itself by this iid
		long[] matchingSubscribers = new long[0];
		     
		long instanceID, transactionID;
		String rawXmlMsg ;
	
		
		boolean resultB=false;
		
		Transaction transaction ;
		Vector<XRegistration> regInstances ;
		FuturesIntf futures ;
		Vector<Future> selfutur; 
		FutureIntf future ;
		Vector<FutureProperties> props; 
		
		XRegistration xreg;
		long xiid, fiid;
		int subscriptType;
		
		// .............................................
		
		futures = messageBoard.getFutures() ;
		regInstances = messageBoard.getRegisteredInstances() ;
		
		 
		
		for (int c=0;c<regInstances.size();c++){
			
			xreg = regInstances.get(c) ;
			xiid = xreg.getInstanceID() ;
			selfutur = futures.getFuturesById(xiid, 0) ;
			
			if (selfutur.size()>0){
				out.print(2,"...checking subscriptions of instance id="+xiid+"...");
			}
			for (int f=0;f<selfutur.size();f++){
				future = selfutur.get(f) ;
				
				props = future.getProperties() ;
				subscriptType = props.get(0).type ;
				
				if (subscriptType== FutureProperties._SIMPLESET ){
					// data type item set or features ?
					
				}
				if (subscriptType== FutureProperties._CONTEXT ){
					// data type item set or features ?
					
				}
				
				
			} // f->
			
		} // c->
		
		return matchingSubscribers;
	}



	@Override
	public long[] checkforSubscriptions(MMMessage mmmessage) {
	
		return null;
	}
	
	
}
